﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using TongTongMall.MallWeb.Core.Enums;
using TongTongMall.UI;

namespace TongTongMall.MallWeb.WebApi.Filter
{
    public class InteriorServiceFilterAttribute : AuthorizeAttribute
    {
        private string AuthorizationKey { get { return "tongtong"; } }

        public override void OnAuthorization(HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext);
        }

        protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            //actionContext.Request.RequestUri.
            if (!AuthorizationKey.Equals(HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query).Get("key")))
            {
                throw new UserFriendlyException((int)ErrCode.ParamErr, "参数错误");
            }
            return true;
        }
    }
}